/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package knowledgebase.model;

import java.io.Serializable;
import java.util.Date;
import java.util.List;
import java.util.Set;
import javax.persistence.*;

/**
 *
 * @author eugene
 */
@Entity
@Table(name = "DOCUMENT")
public class Document implements Serializable, Comparable<Document> {
    
    private static final Long serialVersionUID = 65416841841L;
    
    @Id
    @Column(name = "DOC_ID")
    private String id;
    
    @Column(name = "DOC_NAME")
    private String title;
    
    @Column(name = "DOC_HIERARCHY")
    private String hierarchy;
    
    @Column(name = "CREATION_DATE")
    @Temporal(javax.persistence.TemporalType.DATE)
    private Date creationDate;
    
    @ManyToOne
    @JoinColumn(name = "USER_ID")
    private User owner;
    
    @OneToMany(mappedBy = "parentDocument", cascade = {CascadeType.REFRESH}, fetch = FetchType.EAGER)
    private List<DocumentBlock> blockList;

    public Document() {
    }

    public Document(String id, String title, String hierarchy, Date creationDate, User owner) {
        this.id = id;
        this.title = title;
        this.hierarchy = hierarchy;
        this.creationDate = creationDate;
        this.owner = owner;
    }

    public void setCreationDate(Date creationDate) {
        this.creationDate = creationDate;
    }

    public void setHierarchy(String hierarchy) {
        this.hierarchy = hierarchy;
    }

    public void setId(String id) {
        this.id = id;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public void setOwner(User owner) {
        this.owner = owner;
    }

    public Date getCreationDate() {
        return creationDate;
    }

    public String getHierarchy() {
        return hierarchy;
    }

    public String getId() {
        return id;
    }

    public String getTitle() {
        return title;
    }

    public User getOwner() {
        return owner;
    }
    
    public List<DocumentBlock> getBlockList() {
        return blockList;
    }

    @Override
    public boolean equals(Object obj) {
        if(obj instanceof Document) {
            if(((Document) obj).getId().equals(id)) {
                return true;
            }
        }
        return false;
    }

    @Override
    public int compareTo(Document o) {
        return o.getId().equals(this.getId()) ? 0 : 1;
    }
    
}